package com.turing.system.config;

import com.alibaba.fastjson.JSONObject;
import com.turing.system.service.KeeperWithdrawalsService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;

@Component
public class KeeprRedisConfig implements CommandLineRunner {

    @Resource
    private RedisTemplate redisTemplate;
    @Resource
    private KeeperWithdrawalsService keeperWithdrawalsService;

    private final String SESSIONS_CACHE_PREFIX = "keeper:list:";

    @Override
    public void run(String... args) throws Exception {

        ListOperations ops = redisTemplate.opsForList();
        List<LinkedHashMap<String, Object>> kwList = keeperWithdrawalsService.kwListMap();
        ops.rightPushAll(SESSIONS_CACHE_PREFIX, kwList);

    }
}
